package com.fgi.springframework.context.support;

import com.fgi.springframework.beans.BeansException;

/**
 * Standalone XML application context, taking the context definition files
 * from the class path, interpreting plain paths as class path resource names
 * that include the package path (e.g. "mypackage/myresource.txt"). Useful for
 * test harnesses as well as for application contexts embedded within JARs.
 * <p>
 * XML 文件应用上下文
 * <p>
 * @author HanXu
 * @date 2022/11/24
 * TODO 继承抽象的 XML文件应用上下文，补充 configLocations 参数，存放不同加载bean定义方法的参数
 * TODO 这个类就是最后交给用户使用的类
 **/
public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext {

    /**
     * 存放所有需要读取到应用上下文的文件路径
     */
    private String[] configLocations;

    public ClassPathXmlApplicationContext() {
        this(new String[]{});
    }

    /**
     * 从 XML 中加载 BeanDefinition，并刷新上下文
     *
     * @param configLocations
     * @throws BeansException
     */
    public ClassPathXmlApplicationContext(String configLocations) throws BeansException {
        this(new String[]{configLocations});
    }

    /**
     * 从 XML 中加载 BeanDefinition，并刷新上下文
     * @param configLocations
     * @throws BeansException
     */
    public ClassPathXmlApplicationContext(String[] configLocations) throws BeansException {
        this.configLocations = configLocations;
        refresh();
    }

    @Override
    protected String[] getConfigLocations() {
        return configLocations;
    }

}